package com.af.system.util;

import java.util.regex.Pattern;

/**
 * @author : zhenyun.su
 * @comment : 常用正则表达式
 * @since : 2022/11/9
 */

public class AfRegexUtils {
    public static final String REGEX_MOBILE = "^1[3|4|5|7|8][0-9]{9}$";

    public static void checkRegex(String regex, String value, String hint) throws Exception{
        if (!Pattern.matches(regex, value)){
            throw new Exception(hint);
        }
    }

    public static void checkMobile(String mobile, String hint) throws Exception{
        checkRegex(REGEX_MOBILE, mobile, hint==null ? "Mobile number format error" : hint);
    }

    public static void main(String[] args) {
        try {
            checkMobile("23795467304", "手机号格式错误");
            // checkMobile("23795467304", "手机号格式错误");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
